#include <iostream>
using namespace std;
#include <vector>

int main(int argc, const char *argv[]){
    vector<int> my_vect;
#if 0
    // 把[1, 20]插入到vector中
    for(int i = 0; i < 20; i++){
        my_vect.push_back(i+1);
    }
#else
    my_vect.push_back(1);
    my_vect.push_back(2);
    my_vect.push_back(3);
    my_vect.push_back(3);
    my_vect.push_back(3);
    my_vect.push_back(3);
    my_vect.push_back(4);
#endif
    // 操作前的输出
    for(int i = 0; i < my_vect.size(); i++){
        cout << my_vect[i] << " ";
    }
    cout << endl;
    // 删除所有能被3整除的数
    vector<int>::iterator my_iter = my_vect.begin(); // 迭代器支持初始化的写法
    #if 0
    // 这种写法会跳过元素
    for(my_iter = my_vect.begin(); my_iter != my_vect.end(); my_iter++){
        if(*my_iter % 3 == 0){
            my_vect.erase(my_iter);
        }
    }
    #else
    for(my_iter = my_vect.begin(); my_iter != my_vect.end(); ){
        // 应该使用这样的写法
        if(*my_iter % 3 == 0){
            my_vect.erase(my_iter);
        }else{
            my_iter++;
        }
    }
    #endif
    // 操作后的输出
    for(my_iter = my_vect.begin(); my_iter != my_vect.end(); my_iter++){
        cout << *my_iter << " ";
    }
    cout << endl;

    return 0;
}